package cn.edu.scau.cmi.chenbingquan.client;

import java.util.Scanner;
import cn.edu.scau.cmi.chenbingquan.customize.dao.StudentDAOByJdbc;
import cn.edu.scau.cmi.chenbingquan.customize.dao.TeacherDAOByJdbc;
import cn.edu.scau.cmi.chenbingquan.customize.domain.Student;
import cn.edu.scau.cmi.chenbingquan.customize.domain.Teacher;

// Jdbc连接数据库客户类
public class CustomizeClient {
	public static void main(String[] args) {
		 
		Menu menu = new Menu();
		menu.showMenu();
	}
}

// 菜单类
class Menu {
	StudentDAOByJdbc sdj = new StudentDAOByJdbc();
	TeacherDAOByJdbc tdj = new TeacherDAOByJdbc();
	Scanner input = new Scanner(System.in);
	
	// 显示菜单
	public void showMenu() {
		
		while(true) {
			
			printSelectionInfo();		
			String selection = input.next();		// 选择
			selectFunction(selection);
		}
	}
	
	// 功能选择
	public void selectFunction(String selection) {
		
		switch(selection) {
			case "1": 	System.out.print("请输入学生学号：");
						long student_id1 = input.nextLong();
						System.out.print("请输入学生名字：");
						String name = input.next();
						sdj.newStudent(new Student(student_id1, name));
						break;
						
			case "2":   System.out.print("请输入删除学生学号：");
						long student_id2 = input.nextLong();
						sdj.delete(new Student(student_id2));
						break;
						
			case "3": 	System.out.print("请输入修改的学生学号：");
						long student_id3 = input.nextLong();
						System.out.print("请输入修改的学生名字：");
						String name1 = input.next();
						sdj.update(new Student(student_id3, name1));
						break;
						
			case "4":	System.out.print("请输入要选择老师的学生学号：");
						long student_id4 = input.nextLong();
						System.out.print("请输入要选择的老师工号：");
						long teacher_id1 = input.nextLong();
						sdj.selectTeacher(new Student(student_id4, new Teacher(teacher_id1)));
						break;
						
			case "5": 	sdj.listAllStudents();
						break;
						
			case "6":	System.out.print("请输入老师工号：");
						long teacher_id2 = input.nextLong();
						System.out.print("请输入老师名字：");
						String name2 = input.next();
						tdj.newTeacher(new Teacher(teacher_id2, name2));
						break;
						
			case "7":	System.out.print("请输入删除老师工号：");
						long teacher_id3 = input.nextLong();
						tdj.delete(new Teacher(teacher_id3));
						break;
						
			case "8":	System.out.println("请输入修改的老师工号：");
						long teacher_id4 = input.nextLong();
						System.out.println("请输入修改的老师名字：");
						String name3 = input.next();
						tdj.update(new Teacher(teacher_id4, name3));
						break;
						
			case "9":	System.out.print("请输入要选择学生的老师工号：");
						long teacher_id5 = input.nextLong();
						System.out.print("请输入要选择的学生学号：");
						long student_id5 = input.nextLong();
						tdj.selectStudent(new Teacher(teacher_id5), student_id5);
						break;
						
			case "10":	tdj.listAllTeachers();
						break;
				
			case "e": 	System.out.println("成功退出程序");
						System.exit(0);
						
			default :	System.out.println("输入错误");
		}
	}
	
	// 显示选项信息
	public void printSelectionInfo() {
		
		System.out.println();
		System.out.println("请选择：");
		System.out.println("1. 添加学生");
		System.out.println("2. 删除学生");
		System.out.println("3. 修改学生");
		System.out.println("4. 学生选择老师");
		System.out.println("5. 显示学生表信息");
		System.out.println("6. 添加老师");
		System.out.println("7. 删除老师");
		System.out.println("8. 修改老师");
		System.out.println("9. 老师选择学生");
		System.out.println("10. 显示老师表信息");
		System.out.println("e. 退出程序");
	}
}
